package org.example.lease.web.admin.controller.apartment;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.example.lease.model.entity.PaymentType;
import org.example.lease.common.result.Result;
import org.example.lease.web.admin.service.PaymentTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "支付方式管理")
@RequestMapping("/admin/payment")
@RestController
public class PaymentTypeController {
    @Autowired
    private PaymentTypeService paymentTypeService;

    @Operation(summary = "查询全部支付方式列表")
    @GetMapping("list")
    public Result<List<PaymentType>> listPaymentType(){
        QueryWrapper<PaymentType> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("is_deleted",0);
        List<PaymentType> list = paymentTypeService.list();
        return Result.ok(list);
    }

    @Operation(summary = "保存或更新支付方式")
    @PostMapping("saveOrUpdate")
    public Result saveOrUpdate(@RequestBody PaymentType paymentType){
        paymentTypeService.saveOrUpdate(paymentType);
        return Result.ok("保存支付方式成功");
    }
    @Operation(summary = "根据Id删除支付方式")
    @DeleteMapping("deleteById")
    public Result deleteById(@RequestParam Long id){
        paymentTypeService.removeById(id);
        return Result.ok("删除支付方式成功");
    }
}
